package com.feng.controller;

import com.feng.domain.ResponseResult;
import com.feng.domain.dto.AddLinkDto;
import com.feng.domain.dto.UpdateLinkDto;
import com.feng.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @PreAuthorize("@ps.hasPermission('content:link:query')")
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, String name, String status){
        return linkService.getList(pageNum, pageSize, name, status);
    }

    @PreAuthorize("@ps.hasPermission('content:link:add')")
    @PostMapping
    public ResponseResult addLink(@RequestBody AddLinkDto linkDto){
        return linkService.addLink(linkDto);
    }

    @PreAuthorize("@ps.hasPermission('content:link:edit')")
    @GetMapping("/{id}")
    public ResponseResult updateGetList(@PathVariable("id") Long id){
        return linkService.updateGetList(id);
    }

    @PreAuthorize("@ps.hasPermission('content:link:edit')")
    @PutMapping
    public ResponseResult updateLink(@RequestBody UpdateLinkDto linkDto){
        return linkService.updateLink(linkDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delLink(@PathVariable("id") List<Long> ids){
        return linkService.delLink(ids);
    }
}
